package com.mall.controller;

import com.mall.commons.common.CommonResult;
import com.mall.mapper.SkuStockMapper;
import com.mall.model.domain.PmsSkuStock;
import com.mall.service.SkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sku")
public class SkuStockController {

    @Autowired
    private SkuStockService skuStockService;

    /**
     * 批量更新sku库存信息
     *
     * @param pid
     * @param list
     * @return
     */
    @PostMapping("/update/{pid}")
    public CommonResult batchUpdateByPid(@PathVariable Integer pid, @RequestBody List<PmsSkuStock> list) {
        skuStockService.batchUpdateByPid(pid, list);
        return CommonResult.success(null, "更新成功");
    }


    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param pid
     * @param keyword
     * @return
     */
    @GetMapping("/{pid}")
    public CommonResult querySkuByIdAndSkuCode(@PathVariable Integer pid,String keyword){
      List<PmsSkuStock>  list= skuStockService.querySkuByIdAndSkuCode(pid,keyword);
      return CommonResult.success(list);
    }
}
